from google.appengine.api import users
from google.appengine.ext import webapp
import os
_DEBUG = True
from operation.tools import Tools
from google.appengine.ext.webapp import template


class RequestHandler(webapp.RequestHandler):
    def render(self, template_name, template_values={}):
        user = users.get_current_user()
        if user:
            log_in_out_url = users.create_logout_url(self.request.uri)
        else:
            log_in_out_url = users.create_login_url(self.request.path)
        values = {'user': user,'items':Tools.namelist, 'log_in_out_url': log_in_out_url}
        values.update(template_values)
        directory = os.path.dirname(__file__)
        path = os.path.join(directory, '../templates', template_name)
        self.response.out.write(template.render(path, values, debug=_DEBUG))